<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/echarts.js"></script>
    <link rel="stylesheet" href="../plugins/elementui/index.css">
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>统计分析
            <small>会员数量</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>会员数量</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box"><!--//style="overflow: hidden"-->
            <template>
                <div class="block">
                    <span class="demonstration">日期选择</span>
                    <el-date-picker
                            v-model="value2"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                    >
                    </el-date-picker>
                    <el-button type="primary" @click="query">查询</el-button>
                </div>
            </template>
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <!--折线图-->
            <div id="chart1" style="height:300px;"></div>
            <!--饼图-->
            <span id="chart2" style="width: 30%;height: 300px; float: left; padding-left: 15%"></span>
            <span id="chart3" style="width: 30%;height: 300px; float: right;padding-right: 15%"></span>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/elementui/index.js"></script>
<link rel="stylesheet" href="../plugins/elementui/index.css">
<script type="text/javascript"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            value: [],
            value2: ""
        },

        methods: {
            handleApp() {
                axios.post("http://oms.backend.health:82/report/handleApp.do", this.value).then((response) => {
                    console.log("我是handleApp方法----------------" + response);
                    if (response.data.flag) {
                        memberOption.xAxis.data = response.data.data.monthList;
                        memberOption.series[0].data = response.data.data.memberCount;
                        myChart1.clear();
                        myChart1.setOption(memberOption);

                    }
                }).catch((err) => {
                    console.log(err);
                })
            },
            query: function () {
                if (this.value2 instanceof Array) {
                    let date01 = this.value2[0]
                    let date02 = this.value2[1]
                    let yyMMdd = function (date) {
                        let year = date.getFullYear()
                        let month = date.getMonth() + 1
                        return `${year}-${month < 10 ? "0" : ""}${month}-01`
                    }
                    axios.get("http://oms.backend.health:82/report/getMemberReportBetweenDays.do?"
                        + `start=${yyMMdd(date01)}&end=${yyMMdd(date02)}`).then(setData)


                } else {
                    this.$message("请选择日期")
                }
            }
        }
    })
    ;

    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('chart1'));
    var myChart2 = echarts.init(document.getElementById('chart2'));
    var myChart3 = echarts.init(document.getElementById('chart3'));

    // 使用刚指定的配置项和数据显示图表。
    //myChart.setOption(option);

    function setData(res) {
        myChart1.setOption(
            {
                title: {
                    text: '会员数量'
                },
                tooltip: {},
                legend: {
                    data: ['会员数量']
                },
                xAxis: {
                    data: res.data.data.months
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    name: '会员数量',
                    type: 'line',
                    data: res.data.data.memberCounts
                }]
            });

    }

    var memberOption = {
        title: {
            text: '会员数量'
        },
        tooltip: {},
        legend: {
            data: ['会员数量']
        },
        xAxis: {
            data: []
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            name: '会员数量',
            type: 'line',
            data: []
        }]
    };


    axios.get("http://oms.backend.health:82/report/getMemberReport.do").then((res) => {
        console.log("我是getMemberReport方法----------------" + res);
        memberOption.xAxis.data = res.data.data.months;
        memberOption.series[0].data = res.data.data.memberCount;
        myChart1.clear();
        myChart1.setOption(memberOption);

    });

    // 性别饼图
    axios.get("http://oms.backend.health:82/report/getMemberSexReport.do").then((res) => {
        console.log("我是getMemberSexReport方法----------------" + res);
        myChart2.setOption(
            {
                title: {
                    text: '会员男女占比',
                    subtext: '',
                    x: 'center'
                },
                tooltip: {//提示框组件
                    trigger: 'item',//触发类型，在饼形图中为item
                    formatter: "{a} <br/>{b} : {c} ({d}%)"//提示内容格式
                },
                color: ['#4472C5', '#ED7C30', '#80FF80'],
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: res.data.data.setmealNames
                },
                series: [
                    {
                        name: '会员男女占比',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: res.data.data.setmealCount,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            });
    });

    // 年龄饼图
    axios.get("http://oms.backend.health:82/report/getMemberAgeReport.do").then((res) => {
        console.log("我是getMemberAgeReport方法----------------" + res);
        myChart3.setOption(
            {
                title: {
                    text: '会员年龄占比',
                    subtext: '',
                    x: 'center'
                },
                tooltip: {//提示框组件
                    trigger: 'item',//触发类型，在饼形图中为item
                    formatter: "{a} <br/>{b} : {c} ({d}%)"//提示内容格式
                },
                color: ['#4472C5', '#ED7C30', '#80FF80'],
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: res.data.data.setmealNames
                },
                series: [
                    {
                        name: '会员年龄占比',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: res.data.data.setmealCount,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            });
    });
</script>

</html>
